CC = g++
VERSION = -std=c++0x
CFLAGS = -g -W -Wall #-Wredundant-decls -Wshadow -Wcast-qual -Werror

SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
INCLUDE_DIR = include

VPATH = src:include

TARGET = NetworkDiscover	

SOURCES = $(notdir $(wildcard $(SRC_DIR)/*.cpp))
OBJECTS = $(patsubst %.cpp, %.o, $(SOURCES))

MERLIN_PATH = merlin
MERLIN_TARGET = merlinc

LIB = -lscamperfile

	
$(BIN_DIR)/$(TARGET) : $(addprefix $(OBJ_DIR)/, $(OBJECTS)) 
	$(CC) $(LIB) $^  -o $(BIN_DIR)/$(TARGET) $(CFLAGS) $(VERSION) 

$(OBJ_DIR)/%.o : $(addprefix $(SRC_DIR)/, %.cpp) $(MERLIN_PATH)/$(MERLIN_TARGET)
	$(CC) $(CFLAGS) $(VERSION) -I$(INCLUDE_DIR) -c $< -o $@

$(MERLIN_PATH)/$(MERLIN_TARGET) : $(MERLIN_PATH)/mrinfo.c
	make -C $(MERLIN_PATH) merlinc


### Dependances ###

$(OBJ_DIR)/IPList.o : $(INCLUDE_DIR)/IPList.h
$(OBJ_DIR)/Router.o : $(INCLUDE_DIR)/Router.h $(INCLUDE_DIR)/IPList.h
$(OBJ_DIR)/Readfile.o : $(INCLUDE_DIR)/Readfile.h $(INCLUDE_DIR)/Router.h  \
							$(INCLUDE_DIR)/IPList.h
$(OBJ_DIR)/ScamperHandler.o : $(INCLUDE_DIR)/ScamperHandler.h \
							$(INCLUDE_DIR)/IPList.h $(INCLUDE_DIR)/Router.h

### Command to launch the program with Valgrind ###
valgrind :
	make -C $(BIN_DIR) valgrind



run : 
	make -C $(BIN_DIR) run

clean :
	rm obj/* bin/$(TARGET) $(MERLIN_PATH)/$(MERLIN_TARGET)

mrproper : 
	make -C $(MERLIN_PATH) clean
	rm obj/* bin/$(TARGET) $(MERLIN_PATH)/$(MERLIN_TARGET)

.PHONY : doc
doc :
	rm -rf doc/*
	doxygen Doxyfile

.PHONY : gedit
gedit :	
	gedit src/*.cpp include/*.h Makefile bin/Makefile utilities/Makefile & 
	make -C $(LIB_DIR) gedit 

.PHONY : opendoc
opendoc : 
	firefox doc/html/index.html
